package org.umlviewer.xmiparser;

import org.umlviewer.model.DiagramElement;
import org.umlviewer.model.Relationship;
import org.umlviewer.model.diagram_class.Association;
import org.umlviewer.model.diagram_class.Method;
import org.umlviewer.model.sequence_diagram.Message;

/**
 *
 * @author Rafa
 */
public class RelationshipParser {

    private String idSource;
    private String idDestination;
    private String name;
    //xmi:id de la relacion
    private String relId;
    private int type;
    //atributos propios de los uml:Messages
    private String messageKind;
    private String messageSort;
    private Method method;

    public RelationshipParser(String idSource, String idDestination, int type) {
        this.idSource = idSource;
        this.idDestination = idDestination;
        this.type = type;
        relId= "";
        name = "";
        messageKind = messageSort = "";
        method = new Method();
    }
    
    public RelationshipParser()
    {
        idSource = idDestination = "";
        type = 0;
        relId = "";
        name = "";
        messageKind = messageSort = "";
        method = new Method();
    }

    public String getIdDestination() {
        return idDestination;
    }

    public void setIdDestination(String idDestination) {
        this.idDestination = idDestination;
    }

    public String getIdSource() {
        return idSource;
    }

    public void setIdSource(String idSource) {
        this.idSource = idSource;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getRelId() {
        return relId;
    }

    public void setRelId(String relId) {
        this.relId = relId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }
    
    public Relationship getRelationship(DiagramElement srcElement, DiagramElement dstElement){        
        if(this.type == Relationship.MESSAGE){
            Message m = new Message();
            m.setSource(srcElement);
            m.setDestination(dstElement);
            m.setName(name);
            method.setName(name);
            m.setMethod(method);
            m.setType(type);
            return m;
        }        
        else{
            Association a = new Association(name, type, srcElement, dstElement);
            return a;
        }
        //return null;
    }
    
}
